package com.csun.dsms.task;

import com.alibaba.fastjson.JSONObject;
import com.csun.dsms.mapper.HgReminderConfigMapper;
import com.csun.dsms.model.domain.YcAlert;
import com.csun.dsms.model.domain.YcDevice;
import com.csun.dsms.model.domain.YcDeviceData;
import com.csun.dsms.model.dto.yc.YcDeviceQueryDto;
import com.csun.dsms.model.dto.yc.YcRequestBean;
import com.csun.dsms.model.huang.HgReminderConfig;
import com.csun.dsms.service.HgReminderDataService;
import com.csun.dsms.service.YcAlertService;
import com.csun.dsms.service.YcDeviceDataService;
import com.csun.dsms.service.YcDeviceService;
import com.csun.dsms.utils.DateUtil;
import com.csun.dsms.utils.SmsUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;

@Slf4j
@Component
@EnableScheduling
public class HgQueryDataTask {

    @Resource
    private RedisTemplate<String, String> redis;

    @Resource
    private HgReminderDataService hgReminderDataService;

    @Resource
    private HgReminderConfigMapper hgReminderConfigMapper;



    @Scheduled(cron = "0 0 08 * * ?")
    public void addRemind(){
//        log.info("定时删除上个月的数据");
//        ycDeviceDataService.deleteBfDate();
        //1. 获取当前日;
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        // 获取当前日
        int currentDay = currentDate.getDayOfMonth();
        List<HgReminderConfig> remindConfigList = hgReminderConfigMapper.selectAll();
        if (remindConfigList != null && remindConfigList.size() > 0) {
            for (int i = 0; i < remindConfigList.size(); i++) {
                HgReminderConfig remindConfig = remindConfigList.get(i);
                if (currentDay == remindConfig.getReminderDay()){
                    //只有这种状态才可以发通知
                    sendReminder(remindConfig);
                }
                if (currentDay == remindConfig.getAlertDay()){
                    //只有这种状态才可以发通知
                    sendAlert(remindConfig);
                }
                if (currentDay == remindConfig.getNotifyDay()){
                    //只有这种状态才可以发通知
                    sendNotify(remindConfig);
                }
            }
        }

    }

    private void sendReminder(HgReminderConfig remindConfig) {
        if (remindConfig.getType()!=null && remindConfig.getType() == 1){
            //gdp的

        }

    }

    private void sendAlert(HgReminderConfig remindConfig) {
        if (remindConfig.getType()!=null && remindConfig.getType() == 1){
            //gdp的

        }

    }

    private void sendNotify(HgReminderConfig remindConfig) {
        if (remindConfig.getType()!=null && remindConfig.getType() == 1){
            //gdp的

        }

    }


    /**
     * 每5分钟执行一次
     * 查询报警数据出来
     */
    @Scheduled(cron = "0 0/5 * * * ?")
    public void queryAllDeviceData(){


    }

    /**
     * 每两分钟执行一次
     */
    //0 0/2 * * * ?
    @Scheduled(cron = "0 0/2 * * * ?")
    public void queryRealData(){


    }

    private void addData(YcRequestBean.DataDTO item) {

    }

}
